#include "common.h"

#include "xplane.h"

void set_throttle(int sock, struct sockaddr* dest, float frac)
{
	xplane_data d;
	memset(&d,0,sizeof(xplane_data));
	d.index = 25;
	char buffer[1500];
	d.data[0] = frac;
	d.data[2] = frac;
	d.data[1] = frac;
	d.data[3] = frac;
	d.data[4] = frac;
	d.data[5] = frac;
	d.data[6] = frac;
	d.data[7] = frac;
	memcpy(buffer, "DATA0", 5);
	memcpy(buffer+5, &d, sizeof(xplane_data));
	sendto(sock,buffer,5+sizeof(d),0,(struct sockaddr*)dest,sizeof(struct sockaddr));
}

void set_joystick(int sock, struct sockaddr* dest, float x, float y, float z)
{
	xplane_data d;
	memset(&d,0,sizeof(xplane_data));
	d.index = 8;
	char buffer[1500];
	d.data[0] = -x;
	d.data[1] =  y;
	d.data[2] =  y*0.4;
	d.data[3] = -999.0;
	d.data[4] = -999.0;
	d.data[5] = -999.0;
	d.data[6] = -999.0;
	d.data[7] = -999.0;
	memcpy(buffer, "DATA0", 5);
	memcpy(buffer+5, &d, sizeof(xplane_data));
	sendto(sock,buffer,5+sizeof(d),0,(struct sockaddr*)dest,sizeof(struct sockaddr));
}

void set_gear_brakes(int sock, struct sockaddr* dest, float gear, float brakes)
{
	xplane_data d;
	memset(&d,0,sizeof(xplane_data));
	d.index = 14;
	char buffer[1500];
	d.data[0] = gear;
	d.data[2] = -999.0;
	d.data[1] = brakes; 
	d.data[3] = -999.0;
	d.data[4] = -999.0;
	d.data[5] = -999.0;
	d.data[6] = -999.0;
	d.data[7] = -999.0;
	memcpy(buffer, "DATA0", 5);
	memcpy(buffer+5, &d, sizeof(xplane_data));
	sendto(sock,buffer,5+sizeof(d),0,(struct sockaddr*)dest,sizeof(struct sockaddr));
}

void set_trim_flaps(int sock, struct sockaddr* dest, float trim, float flaps)
{
	xplane_data d;
	memset(&d,0,sizeof(xplane_data));
	d.index = 13;
	char buffer[1500];
	d.data[0] = trim;
	d.data[2] = -999.0;
	d.data[1] = -999.0;
	d.data[3] = flaps;
	d.data[4] = -999.0;
	d.data[5] = -999.0;
	d.data[6] = -999.0;
	d.data[7] = -999.0;
	memcpy(buffer, "DATA0", 5);
	memcpy(buffer+5, &d, sizeof(xplane_data));
	sendto(sock,buffer,5+sizeof(d),0,(struct sockaddr*)dest,sizeof(struct sockaddr));
}
